Skip to content

[Code Update - Chapter 13] Code update for MP Reactive Messaging 3.0.1#75

Open
ttelang wants to merge 1 commit into
microprofile:mainfrom
ttelang:code-update-mp-reactive-messaging-3.0.1
Open

[Code Update - Chapter 13] Code update for MP Reactive Messaging 3.0.1#75
ttelang wants to merge 1 commit into
microprofile:mainfrom
ttelang:code-update-mp-reactive-messaging-3.0.1

Conversation

@ttelang
Copy link
Copy Markdown
Contributor

@ttelang ttelang commented Apr 24, 2026

Overview

This pull request adds code examples for Chapter 13 of the MicroProfile tutorial, demonstrating practical implementation of MicroProfile Reactive Messaging 3.0.1 in a multi-service e-commerce application.

Changes

New Code Examples

Order Service (code/chapter13/order/)

  • Full REST API for order management with OpenAPI documentation
  • Order and OrderItem entities with Jakarta Persistence support
  • In-memory repository pattern with CRUD operations
  • Order status lifecycle: CREATEDPAIDPROCESSINGSHIPPEDDELIVERED
  • Integration with MicroProfile Reactive Messaging for async event handling
  • OrderService with transaction management and event emission
  • OrderStatusEventHandler to consume payment authorization events
  • NotificationService for order status change notifications

Payment Service (code/chapter13/payment/)

  • Payment request processing with reactive messaging integration
  • PaymentRequestHandler for consuming order-created events and emitting payment-authorized
  • MicroProfile REST Client examples with multiple implementations:
    • ProductClient - Basic REST client with exception mapping
    • ProductClientWithFilters - Advanced client with authentication, correlation IDs, and logging filters
    • ProductJakartaRestClient - Low-level Jakarta REST client using ClientBuilder
  • Custom response exception mappers for error handling
  • Configuration source implementation for dynamic properties
  • Support for both in-memory and Kafka-based messaging

API Endpoints

Order Management:

  • GET /api/orders - List all orders
  • GET /api/orders/{id} - Get order by ID
  • GET /api/orders/user/{userId} - Get user's orders
  • GET /api/orders/status/{status} - Filter by status
  • POST /api/orders - Create new order
  • PUT /api/orders/{id} - Update order
  • PATCH /api/orders/{id}/status/{status} - Update status
  • DELETE /api/orders/{id} - Delete order

Order Items:

  • GET /api/orderItems/{id} - Get item
  • GET /api/orderItems/order/{orderId} - Get items for order
  • POST /api/orderItems/order/{orderId} - Add item
  • PUT /api/orderItems/{id} - Update item
  • DELETE /api/orderItems/{id} - Remove item

Configuration

  • MicroProfile Config properties for Kafka connectivity
  • OpenAPI annotations for automatic API documentation
  • Support for both development (in-memory) and production (Kafka) deployments

Architecture Highlights

Hybrid REST + Reactive Messaging Pattern:

  • REST for immediate request/response operations (checkout, queries, admin tasks)
  • Reactive Messaging for asynchronous workflows (payment, inventory, shipping)

Event-Driven Workflow:

  1. Shopping Cart initiates checkout via REST
  2. Order Service persists order and emits order-created event
  3. Payment Service consumes event and emits payment-authorized or payment-failed
  4. Inventory Service consumes payment-authorized and emits reservation outcomes
  5. Shipment Service consumes inventory events and manages logistics
  6. Order Service normalizes all events into order-status-events for downstream consumers

Channel Definitions

  • order-created - Published by Order Service, consumed by Payment Service
  • payment-authorized - Published by Payment Service, consumed by Order/Inventory Services
  • payment-failed - Published by Payment Service, consumed by Order Service
  • inventory-reserved - Published by Inventory Service, consumed by Shipment/Order Services
  • inventory-rejected - Published by Inventory Service, consumed by Order Service
  • shipment-created, shipment-dispatched, shipment-delivered - Shipment lifecycle events

Design Concepts Demonstrated

  • Separation of Concerns - Each microservice owns its data and lifecycle
  • Scalability - Event-driven architecture allows independent service scaling
  • Resilience - Async messaging decouples services, improving fault tolerance
  • Developer Experience - Clean REST + Messaging patterns with full OpenAPI support

Testing & Documentation

  • Comprehensive JavaDoc throughout all classes
  • README files with setup and deployment instructions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant